document.ready(function() {
    webSpinner.spin(getItem('loadSpin'));

    setValue('menuid', getUrlParam('menuid'));
    getSortationList();
    queryKey('ok', 'yes');
});

function getSortationList() {
    var param = {};
    param.ctrl = 'other';
    param.func = 'getSortationList';

    sendAjax(param, function(result) {
        loadOptionsItem2('optionItemFloatDiv2', 'sortationInfo', result.sortationList, '分类');
    });
}

function queryKey(flag, permission = 'no') {
    resetPageBar(flag);

    var param = {};
    param.ctrl = 'other';
    param.func = 'getOtherList';
    param.status = getAjaxValue('statusInfo');
    param.sortation = getAjaxValue('sortationInfo');
    param.page = getAjaxValue('page');
    param.menuid = getAjaxValue('menuid');
    param.permission = permission;

    sendAjax(param, function(result) {
        other.list = result.otherList;

        if (result.permission != null && result.permission != '') {
            other.permission = result.permission;
            setDisplay('addInfoBtn', other.permission.addinfo == 'yes' ? '' : 'none');
        }

        initPageBar(result.allPages);
        setHtml('listCount', result.listCount);

        setDisplay('loadSpin', 'none');
        setDisplay('mainBg', '');
        webSpinner.spin();
    });
}

function addOther() {
    toUrl('console.php?m=other&c=add&menuid=' + getValue('menuid'));
}

function viewOther(id) {
    openSlipIframeDiv('console.php?m=other&c=info&otherid=' + id + '&menuid=' + getValue('menuid'));
}

function putOther(id) {
    setValue('tempid', id);
    openConfirm('确定发布吗？', function() {
        var param = {};
        param.ctrl = 'other';
        param.func = 'putOther';
        param.otherid = getAjaxValue('tempid');

        sendAjax(param, function(result) {
            submitRecord('edit', '其他服务列表页', '发布', getValue('tempid'));
            queryKey('page');
        });
    });
}

function retrieveOther(id) {
    setValue('tempid', id);
    openConfirm('确定回收吗？', function() {
        var param = {};
        param.ctrl = 'other';
        param.func = 'retrieveOther';
        param.otherid = getAjaxValue('tempid');

        sendAjax(param, function(result) {
            submitRecord('edit', '其他服务列表页', '回收', getValue('tempid'));
            queryKey('page');
        });
    });
}

function pullOther(id) {
    setValue('tempid', id);
    openConfirm('确定下架吗？', function() {
        var param = {};
        param.ctrl = 'other';
        param.func = 'pullOther';
        param.otherid = getAjaxValue('tempid');

        sendAjax(param, function(result) {
            submitRecord('edit', '其他服务列表页', '下架', getValue('tempid'));
            queryKey('page');
        });
    });
}

function restoreOther(id) {
    setValue('tempid', id);
    openConfirm('确定恢复吗？', function() {
        var param = {};
        param.ctrl = 'other';
        param.func = 'restoreOther';
        param.otherid = getAjaxValue('tempid');

        sendAjax(param, function(result) {
            submitRecord('edit', '其他服务列表页', '恢复', getValue('tempid'));
            queryKey('page');
        });
    });
}

function viewLog(id) {
    openSlipIframeDiv('console.php?m=other&c=log&association=' + id + '&title=' + escape('其他服务管理'));
}

function pushToTweet(id, title, sortation) {
    var param = {};
    param.ctrl = 'tweet';
    param.func = 'pushToTweet';
    param.infoid = id;
    param.title = encodeURIComponent(title);
    param.sortation = encodeURIComponent(sortation);

    sendAjax(param, function(result) {
        showTip('文章已推选至公众号管理员审核');
    });
}